import { calculatePlayerScoresCore } from '../utils/scoreCalculatorCore';

self.onmessage = (event) => {
    const { id, payload } = event.data || {};
    if (typeof id === 'undefined') {
        return;
    }
    try {
        const { playersWithScores, serverPayload } = calculatePlayerScoresCore(payload);
        self.postMessage({
            id,
            result: playersWithScores,
            serverPayload
        });
    } catch (error) {
        self.postMessage({
            id,
            error: error?.message || 'score worker execution failed'
        });
    }
};
